package com.lagou.test;


import com.lagou.dao.IUserMapper;
import com.lagou.io.Resources;
import com.lagou.pojo.User;
import com.lagou.sqlSession.SqlSession;
import com.lagou.sqlSession.SqlSessionFactory;
import com.lagou.sqlSession.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;

public class IPersistence {
    @Test
    public void test() throws Exception {
        InputStream resourceAsSteam = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsSteam);
        SqlSession sqlSession = sqlSessionFactory.openSession();


        IUserMapper userDao = sqlSession.getMapper(IUserMapper.class);
        //1、update更新操作
        User user = new User();
        user.setId(1);
        user.setName("bob222333");
        userDao.updateUser(user);

        //2、insert插入操作
        User user1 = new User();
        user1.setId(3);
        user1.setName("lisa");
        userDao.insertUser(user1);

        //3、delete删除操作
        userDao.deleteUser(user1);

    }
}
